﻿using eslib.tools.config;
using NLog;
using NLog.LayoutRenderers;

namespace ArticleClientLib
{
    public class JsonResult<T>
    {
        /// <summary>
        /// 执行成功返回true
        /// </summary>
        public bool success { get; set; }

        /// <summary>
        /// 错误代码，成功返回0,异常返回错误代码(对应enum)
        /// </summary>
        public int errcode { get; set; }

        /// <summary>
        /// 附加消息
        /// </summary>
        public string msg { get; set; }

        /// <summary>
        /// 绑定对象
        /// </summary>
        public T data { get; set; }

        public JsonResult() { }

        public static JsonResult<T> FromString(string json)
        {
            try
            {
                return GenericJsonConfig.LoadFromString<JsonResult<T>>(json);
            }
            catch (Exception e)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.Error("解释json时异常:" + json);
                throw new Exception("解释json时异常:" + json);
            }
        }
    }

}